<template>
  <div>
    <UploadExce :on-success="success" />
  </div>
</template>

<script>
import { importEmployee } from '@/api/employees'
export default {
  methods: {
    async success({ header, results }) {
      // console.log(results)
      // formData: {
      //   username: '',
      //   mobile: '',
      //   formOfEmployment: '',
      //   workNumber: '',
      //   departmentName: '',
      //   timeOfEntry: '',
      //   correctionTime: ''
      // }
      const userRelations = {
        '入职日期': 'timeOfEntry',
        '手机号': 'mobile',
        '姓名': 'username',
        '转正日期': 'correctionTime',
        '工号': 'workNumber'
      }
      // const arr = []
      // result.forEach(obj => {
      //   const userInfo = {}
      //   Object.keys(obj).forEach(key => {
      //     // 现在key是中文
      //     // 将中文对应的值 替换为英文
      //     userInfo[userRelations[key]] = obj[key]
      //     arr.push(userInfo)
      //   })
      // })
      // console.log(arr)

      const newArr = results.map(obj => {
        const userInfo = {}
        Object.keys(obj).forEach(key => {
          userInfo[userRelations[key]] = obj[key]
        })
        return userInfo
      })
      await importEmployee(newArr)
      this.$message.success('批量导入成功！')
      this.$router.back()
    }
  }
}
</script>

<style>

</style>
